<script setup lang="ts">
import { inject, ref } from 'vue'
import { useActiveOp } from '../../hooks/useActiveOp'

const commonButtons = ref([
  {
    label: 'window', //界面显示的信息
    value: 'window', //发送给后端的属性
    icon: '' // 图标
  },
  {
    label: 'pan',
    value: 'pan',
    icon: 'markRaw(HandMove)'
  },
  {
    label: 'scroll',
    value: 'scroll',
    icon: 'markRaw(ChevronUpDown16Filled)'
  },
  {
    label: 'zoom',
    value: 'zoom',
    icon: 'markRaw(ZoomIn)'
  }
])
const measureOpButtons = ref([
  {
    label: 'line',
    value: 'line',
    icon: 'markRaw(Ruler)'
  },
  {
    label: 'angle',
    value: 'angle',
    icon: 'markRaw(Angle)'
  },
  {
    label: 'ellipse',
    value: 'ellipse',
    icon: 'markRaw(EllipseOutline)'

  },
  {
    label: 'rectangle',
    value: 'rectangle',
    icon: 'markRaw(RectangleLandscape12Regular)'
  }
])
const flipButtons = ref([
  {
    type: 'status',
    label: 'hor flip',
    value: 'horFlip'
  },
  {
    type: 'status',
    label: 'ver flip',
    value: 'verFlip'
  }
])
const rotateButtons = ref([
  {
    label: 'CW90',
    value: 'CW90'
  },
  {
    label: 'CCW90',
    value: 'CCW90'
  }
])
const resetButtons = ref([
  {
    label: 'measure',
    value: 'resetMeasure'
  },
  {
    label: 'window',
    value: 'resetWindow'
  },
  {
    label: 'zoom',
    value: 'resetZoom',
    disabled: true
  },
  {
    label: 'all',
    value: 'resetAll'
  }
])


const viewStatus = defineModel('viewStatus') as any
const emits = defineEmits(['rotate', 'reset'])
const {
  activeOp,
  setActiveOp
} = useActiveOp()

const handleRotate = (subType) => {
  setActiveOp({
    type: 'rotate',
    subType: subType
  })
  emits('rotate', subType)
}

const handleReset = (subType) => {
  setActiveOp({
    type: 'reset',
    subType: subType
  })
  emits('reset', subType)
}


</script>

<template>
  <el-scrollbar height="350px" class="pb-[20px]">
    <div class="mb-[10px]">
      <template v-for="item in commonButtons">
        <el-button
          class="w-full"
          @click="setActiveOp({
                type:item.value,
                subType: item.value
            })"
          :type="activeOp.type === item.value ? 'primary':''">{{
            item.value
          }}
        </el-button>
      </template>
    </div>

    <div class="mb-[10px]" >
      <template v-for="btn in measureOpButtons">
        <el-button
          class="w-full !ml-0"
          @click="setActiveOp({
      type:'measure',
      subType: btn.value
      })"
          :type="activeOp.type ==='measure' && activeOp.subType === btn.label ? 'primary':''"
        >
          {{ btn.value }}
        </el-button>
      </template>
    </div>
    <div>
      <template v-for="btn in flipButtons">
        <div class="bg-white mt-[5px]">
          <span class="text-sm">{{ btn.value }}</span>
          <el-switch v-model="viewStatus[btn.value]"></el-switch>
        </div>
      </template>
    </div>
    <div class="mb-[10px]" >
      <template v-for="btn in rotateButtons">
        <el-button
          class="w-full !ml-0"
          @click="handleRotate(btn.value)"
        >{{ btn.label }}
        </el-button>
      </template>
    </div>

    <div>
      <span>Reset</span>
      <template v-for="btn in resetButtons">
        <el-button
          class="w-full reset-btn"
          :disabled="btn.disabled"
          @click="handleReset(btn.value)"
        >{{
            btn.label
          }}
        </el-button>
      </template>
    </div>
  </el-scrollbar>
</template>

<style scoped>
.btnContainer {
  @apply w-full flex flex-col pl-[5px] pt-[10px] flex-1 overscroll-contain;
  height: calc(100% - 100px);
  width: 100%;
}

.btnWrapper {
  width: calc(100% - 10px);
}

.el-button {
  margin-left: 0px !important;
}

</style>
